package net.lainiao.morethread.Chapter2.demo2;

/**
 * Created by Administrator on 2017/2/28.
 */
public class Yingyuan {
    private long chang1;
    private long chang2;
    private Object obj1 = new Object();
    private Object obj2 = new Object();
    public Yingyuan(){
        chang1=20;
        chang2=20;
    }

    public void sellChang1(long num) {
        synchronized (obj1){
            chang1 -= num;
        }
    }

    public void returnChang1(long num) {
        synchronized (obj1){
            chang1 += num;
        }
    }

    public void sellChang2(long num){
        synchronized (obj2){

            chang2-=num;
        }
    }

    public void returnChang2(long num){
        synchronized (obj2){

            chang2+=num;
        }

    }

    public long getChang1() {
        return chang1;
    }

    public void setChang1(long chang1) {
        this.chang1 = chang1;
    }

    public long getChang2() {
        return chang2;
    }

    public void setChang2(long chang2) {
        this.chang2 = chang2;
    }


}
